#ifndef _XMLUTILS_H_
#define _XMLUTILS_H_

#include "TinyXML/tinyxml.h"

namespace XmlUtils {

	bool WriteTextToFile(const char* pFile, const char* pText);

	TiXmlElement* GetElement(TiXmlElement* pElement, const char* name);

	const char* GetText(TiXmlElement* pElement);
	const char* GetText(TiXmlElement* pElement, const char* name);

	template<typename T>
	bool GetValue(TiXmlElement* pElement, T& value, float fScale=1.0f) {
		const char* pValue = GetText(pElement);
		if(!pValue) return false;
		value = (T)(atof(pValue)*fScale);
		return true;
	}
	bool GetValue(TiXmlElement* pElement, char* value, size_t len);
	bool GetValue(TiXmlElement* pElement, bool& value);
	template<typename T>
	bool GetValue(TiXmlElement* pElement, const char* name, T& value, float fScale=1.0f) {
		const char* pValue = GetText(pElement, name);
		if(!pValue) return false;
		value = (T)(atof(pValue)*fScale);
		return true;
	}
	bool GetValue(TiXmlElement* pElement, const char* name, char* value, size_t len);
	bool GetValue(TiXmlElement* pElement, const char* name, bool& value);

	const char* GetAttribute(TiXmlElement* pElement, const char* name);
	template<typename T>
	bool GetAttribute(TiXmlElement* pElement, const char* name, T& value, float fScale=1.0f) {
		const char* pValue = GetAttribute(pElement, name);
		if(!pValue) return false;
		value = (T)(atof(pValue)*fScale);
		return true;
	}
	bool GetAttribute(TiXmlElement* pElement, const char* name, char* value, size_t len);
	bool GetAttribute(TiXmlElement* pElement, const char* name, bool& value);
};

#endif
